//
//  ZMeVC.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/10.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZMeVC.h"
#import "ZTableViewController.h"
#import "ZAboutMeVC.h"
#import "ZHelpVC.h"
#import "ZZDeviceManager.h"
@interface ZMeVC ()

@property (nonatomic, weak)UIViewController *vc;

@property (nonatomic, weak)ZZDeviceManager *devicemanager;

@end

@implementation ZMeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationItem.titleView = [UIImageView zImageViewWithImage:@"img_logo"];
    self.navigationItem.rightBarButtonItem = [self zNavItemWithImage:@"icon_lanmu" shouldOriginal:YES andSelector:@selector(rightNavItemClick)];
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ZTableViewController" bundle:nil];
    ZTableViewController *vc = (ZTableViewController *)[sb instantiateInitialViewController];
    vc.view.frame = Z_SCREEN;
    self.vc  = vc;
    [self.view addSubview:vc.view];
    [self addChildViewController:vc];
    
    vc.selectCell = ^(NSIndexPath *indexPath) {
        
        switch (indexPath.row) {
            case 0:// 离线设备管理
            {
                
            }
                
                break;
            case 1:// 帮助
            {
                ZHelpVC *helpVc = [[UIStoryboard storyboardWithName:@"ZHelpVC" bundle:nil] instantiateInitialViewController];
                [self.navigationController pushViewController:helpVc animated:YES];
            }
                
                break;
            case 2:// 关于我们
            {
                ZAboutMeVC *meVc = [[ZAboutMeVC alloc] init];
                [self.navigationController pushViewController:meVc animated:YES];
            }
                
                break;
                
                
            default:
                break;
        }
    };
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear: animated];
    self.vc.view.frame = CGRectMake(0, 64, Z_SCREEN_WIDTH, Z_SCREEN_HEIGHT - 64);

    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
     
}

#pragma mark - func
- (void)rightNavItemClick {
    
    if (self.devicemanager) {
        
        [self.devicemanager removeFromSuperview];
        self.devicemanager = nil;
        return;
    }
    
    ZZDeviceManager *manager = [ZZDeviceManager xibInstance];
    manager.vc = self;
    
    self.devicemanager = manager;
    manager.frame = CGRectMake(Z_SCREEN_WIDTH, 64, Z_SCREEN_WIDTH, Z_SCREEN_HEIGHT - 64);
    [self.tabBarController.view addSubview:manager];
    
    [UIView animateWithDuration:0.4 animations:^{
        
        manager.x = 0;
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}



@end
